using DataModels.Enumerations;
using DataModels.Models.Context;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;

namespace DataModels.Models
{
    [Table("DataInputMethod")]
    public partial class DataInputMethod
    {
        internal const string SMS = "SMS";
        internal const string SMS_DESCRIPTION = "Short Message Services";

        internal const string DESKTOP_DATA_CAPTURE = "Desktop Data Capture";
        internal const string DESKTOP_DATA_CAPTURE_DESCRIPTION = "Desktop client - Data Capture";

        internal const string MOBILE_DATA_CAPTURE = "Mobile Data Capture";
        internal const string MOBILE_DATA_CAPTURE_DESCRIPTION = "Mobile client - Data Capture";

        internal const string WEB_DATA_CAPTURE = "Web Data Capture";
        internal const string WEB_DATA_CAPTURE_DESCRIPTION = "Web client - Data Capture";

        internal const string DESKTOP_BULK_DATA_IMPORT = "Desktop Bulk Data Import";
        internal const string DESKTOP_BULK_DATA_IMPORT_DESCRIPTION = "Desktop client - Bulk Data Import";

        internal const string MOBILE_BULK_DATA_IMPORT = "Mobile Bulk Data Import";
        internal const string MOBILE_BULK_DATA_IMPORT_DESCRIPTION = "Mobile client - Bulk Data Import";

        internal const string WEB_BULK_DATA_IMPORT = "Web Bulk Data Import";
        internal const string WEB_BULK_DATA_IMPORT_DESCRIPTION = "Web client - Bulk Data Import";

        internal const string DHIS2_DATA_IMPORT = "DHIS2 Data Import";
        internal const string DHIS2_DATA_IMPORT_DESCRIPTION = "DHIS2 Data Import";

        internal const string OTHER_DATA_INPUT_METHODS = "Other Input Methods";
        internal const string OTHER_DATA_INPUT_METHODS_DESCRIPTION = "Other Input Methods";

        internal const string DESKTOP_DATA_MERGING = "Desktop Data Merging";
        internal const string DESKTOP_DATA_MERGING_DESCRIPTION = "Desktop client - Data Merging";

        internal const string MOBILE_DATA_MERGING = "Mobile Data Merging";
        internal const string MOBILE_DATA_MERGING_DESCRIPTION = "Mobile client - Data Merging";

        internal const string WEB_DATA_MERGING = "Web Data Merging";
        internal const string WEB_DATA_MERGING_DESCRIPTION = "Web client - Data Merging";

        public static DataInputMethod GetDataInputMethod(DataInputingMethod method)
        {
            string methodName = GetDataInputMethodName(method);
            DataInputMethod inputMethod = null;

            if (!string.IsNullOrWhiteSpace(methodName))
            {
                using (var db = new IQSMS_TestDBContext())
                {
                    inputMethod = (from i in db.DataInputMethods
                                   where i.Name == methodName
                                   select i).FirstOrDefault();
                }
            }

            return inputMethod;
        }

        private static string GetDataInputMethodName(DataInputingMethod method)
        {
            switch (method)
            {
                case DataInputingMethod.SMS: return SMS;
                case DataInputingMethod.DESKTOP_DATA_CAPTURE: return DESKTOP_DATA_CAPTURE;
                case DataInputingMethod.MOBILE_DATA_CAPTURE: return MOBILE_DATA_CAPTURE;
                case DataInputingMethod.WEB_DATA_CAPTURE: return WEB_DATA_CAPTURE;
                case DataInputingMethod.DESKTOP_BULK_DATA_IMPORT: return DESKTOP_BULK_DATA_IMPORT;
                case DataInputingMethod.MOBILE_BULK_DATA_IMPORT: return MOBILE_BULK_DATA_IMPORT;
                case DataInputingMethod.WEB_BULK_DATA_IMPORT: return WEB_BULK_DATA_IMPORT;
                case DataInputingMethod.DHIS2_IMPORT: return DHIS2_DATA_IMPORT;
                case DataInputingMethod.OTHER_METHODS: return OTHER_DATA_INPUT_METHODS;
                case DataInputingMethod.DESKTOP_DATA_MERGING: return DESKTOP_DATA_MERGING;
                case DataInputingMethod.MOBILE_DATA_MERGING: return MOBILE_DATA_MERGING;
                case DataInputingMethod.WEB_DATA_MERGING: return WEB_DATA_MERGING;
                default: return OTHER_DATA_INPUT_METHODS;
            }
        }

        public DataInputMethod()
        {
            this.ANCFormMetadatas = new List<ANCFormMetadata>();
        }

        [Key]
        public int Id { get; set; }

        [Required]
        [StringLength(255)]
        public string Name { get; set; }

        [StringLength(1000)]
        public string Description { get; set; }
        public virtual List<ANCFormMetadata> ANCFormMetadatas { get; set; }
    }
}
